﻿Imports System.Data.SqlClient

Public Class frmBuscarLiquidaciones
    Private mstrCondicion As String
    Private mstrValor As String
    Dim mdsDatos As New DataSet
    Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    Public WriteOnly Property Condicion() As String
        Set(ByVal value As String)
            mstrCondicion = value
        End Set
    End Property
    Public ReadOnly Property Valor() As String
        Get
            Valor = mstrValor
        End Get
    End Property
    Private Sub frmBuscarLiquidaciones_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtBuscar.Text = frmLiquidacion.txtAutobus.Text
        ActualizarTodas()
    End Sub
    Sub ActualizarTodas()
        Windows.Forms.Cursor.Current = Cursors.WaitCursor
        dgBuscar.Rows.Clear()

        Dim strNombre As String
        Dim cnconn As New SqlConnection
        Dim strSql As String = ""
        Dim cmdBuscar As New SqlCommand
        Dim cmdAsignar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim fecha As Date

        Try
            strNombre = UCase(txtBuscar.Text.Trim)
            strNombre = "%" & strNombre.Replace(" ", "%") & "%"

            cnconn.ConnectionString = CitraConnection
            cnconn.Open()

            cmdBuscar.Connection = cnconn
            cmdAsignar.Connection = cnconn

            strSql = "Select IdLiquidacion,Fecha,General,Preferencial,TotalBoletos,Vueltas,Liquidacion,NombreOperador,NoEconomico " & _
                     "From Liquidacion " & _
                     "WHERE upper(NoEconomico) Like '" & strNombre & "' " & mstrCondicion & " OR upper(NombreOperador) like '" & strNombre & "' " & mstrCondicion & " Order By fecha DESC"

            cmdBuscar.CommandText = strSql
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                fecha = rdBuscar("fecha")
                fecha = fecha.Day & "/" & fecha.Month & "/" & fecha.Year
                dgBuscar.Rows.Add(rdBuscar("IdLiquidacion"), rdBuscar("NoEconomico").ToString.Trim, rdBuscar("NombreOperador").ToString.Trim, fecha, rdBuscar("General"), rdBuscar("Preferencial"), rdBuscar("TotalBoletos"), rdBuscar("Vueltas"), rdBuscar("Liquidacion"))

            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try


        

       
    End Sub
   


    Private Sub txtBuscar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.TextChanged
        ActualizarTodas()
    End Sub

    Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
        Dim strRetVal As String = ""

        Try
            strRetVal = CStr(dgBuscar.Item(0, dgBuscar.CurrentCell.RowIndex).Value)
        Catch ex As Exception
            strRetVal = ""
        Finally
            mstrValor = strRetVal.Trim
        End Try

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
    Private Sub dgResult_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgBuscar.CellDoubleClick

        RadButton2_Click(Me, System.EventArgs.Empty)

    End Sub

    Private Sub dgResult_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgBuscar.KeyDown

        If e.KeyCode = Keys.Enter Then
            RadButton2_Click(Me, System.EventArgs.Empty)
        End If

    End Sub

   
    Private Sub dgBuscar_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgBuscar.CellContentClick

    End Sub
End Class